<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class ajusteM extends CI_Model {

    public function __construct() {
        $this->load->database();
    }

    public function crearAjuste($valor, $descripcion, $idReserva, $usuario, $tipo) {
        $query = "INSERT INTO ajuste(id_reserva,fecha,valor,descripcion,usuario_encargado,tipo) VALUES('$idReserva',now(),'$valor','$descripcion','$usuario','$tipo')";
        return $this->db->query($query);
    }

    public function obtenerAjustes($idReserva) {
        $query = "SELECT  COALESCE(SUM(valor),0) totalAjuste from ajuste WHERE id_reserva='$idReserva'";
        return $this->db->query($query)->result();
    }

    public function totalAjusteAlojamiento($idReserva) {
        $query = "SELECT  COALESCE(SUM(valor),0) totalAjuste from ajuste WHERE id_reserva='$idReserva' AND tipo='alojamiento'";
        return $this->db->query($query)->result();
    }
    public function listarAjustesByTipo($idReserva,$tipo) {
        $query = "SELECT  * from ajuste WHERE id_reserva='$idReserva' AND tipo='$tipo'";
        return $this->db->query($query)->result();
    }


}